import { Component, OnInit } from '@angular/core';
import { Course } from '../../model/course';
import { Student } from '../../model/Student';
import { Book } from '../../model/book';

@Component({
  selector: 'app-courseindex',
  templateUrl: './courseindex.component.html',
  styleUrls: ['./courseindex.component.css']
})
export class CourseindexComponent implements OnInit {
  // c:Course;
  cl:Array<Course>;
  sl:Array<Student>;
  bl:Array<Book>;

  constructor() { }

  ngOnInit() {
    this.initCourse();
    this.setCourse();
    this.initStudent();
    this.initBook();
  }

  initCourse(){
    // this.c=new Course();
    // this.c.name="综合项目开发"
    // this.c.teacher="张晓献"
    // this.c.classroom="1-302"
    // this.c.student="2016级计算机科学与技术2班"

    this.cl=new Array();
    for(let i=0;i<25;i++){
      let c=new Course();
      c.id=i;
      this.cl.push(c);

    }
  }

  setCourse(){
    let p=new Course();
    p.name="RFID原理应用"
    p.teacher="陈君华"
    p.classroom="2-302"
    p.student="2016级计算机科学与技术2班"
    p.id=7
    // this.cl[p.id]=p;

    let q=new Course();
    q.name="RFID原理应用"
    q.teacher="陈君华"
    q.classroom="2-302"
    q.student="2016级计算机科学与技术2班"
    q.id=8

    let searchresult=new Array();
    searchresult.push(p);
    searchresult.push(q);

    for(let x of searchresult){
      this.cl[x.id]=x;
    }
  }

  initStudent(){
    this.sl=new Array();
    for(let i=0;i<30;i++){
      let s=new Student();
      s.id="主键"+i;
      s.name="班级"+i;
      this.sl.push(s);
    }
  }

  initBook(){
    this.bl=new Array();
    for(let i=0;i<30;i++){
      let b=new Book();
      b.id="主键"+i;
      b.name="课程"+i;
      this.bl.push(b);
    }
  }

  onStudentSelect(s:Student){
    console.dir(s);
  }
}
